Answer the following questions and complete the exercises in
RMarkdown. Please embed all of your code and push your final work to
your repository. Your final lab report should be organized, clean, and
run free from errors. Remember, you must remove the # for
the included code chunks to run. Be sure to add your name to the author
header above. For any included plots, make sure they are clearly
labeled. You are free to use any plot type that you feel best
communicates the results of your analysis.
Make sure to use the formatting conventions of RMarkdown to make your report neat and clean!
library(tidyverse)
library(janitor)
library(ggmap)
We will use two separate data sets for this homework.
grizzly <- read_csv("data/bear-sightings.csv")%>% clean_names() %>%
filter(longitude !="NA" & latitude !="NA") %>% # pulling out NA locations
mutate(longitude = as.numeric(longitude)) # converting longitude to numeric
## Rows: 494 Columns: 3
## ── Column specification ────────────────────────────────────────────────────────
## Delimiter: ","
## dbl (3): bear.id, longitude, latitude
##
## ℹ Use `spec()` to retrieve the full column specification for this data.
## ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
wolves <- read_csv("data/wolves_dataset.csv")%>% clean_names()
## Rows: 1986 Columns: 23
## ── Column specification ────────────────────────────────────────────────────────
## Delimiter: ","
## chr (4): pop, age.cat, sex, color
## dbl (19): year, lat, long, habitat, human, pop.density, pack.size, standard....
##
## ℹ Use `spec()` to retrieve the full column specification for this data.
## ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
#%>%
#filter(longitude !="NA" & latitude !="NA") %>% # pulling out NA locations
#mutate(longitude = as.numeric(longitude)) # converting longitude to numeric
grizzly data and evaluate its structure.glimpse(grizzly)
## Rows: 494
## Columns: 3
## $ bear_id <dbl> 7, 57, 69, 75, 104, 108, 115, 116, 125, 135, 137, 162, 185, …
## $ longitude <dbl> -148.9560, -152.6228, -144.9374, -152.8485, -143.2948, -149.…
## $ latitude <dbl> 62.65822, 58.35064, 62.38227, 59.90122, 61.07311, 62.91605, …
summary(grizzly)
## bear_id longitude latitude
## Min. : 7 Min. :-166.2 Min. :55.02
## 1st Qu.:2569 1st Qu.:-154.2 1st Qu.:58.13
## Median :4822 Median :-151.0 Median :60.97
## Mean :4935 Mean :-149.1 Mean :61.41
## 3rd Qu.:7387 3rd Qu.:-145.6 3rd Qu.:64.13
## Max. :9996 Max. :-131.3 Max. :70.37
grizzly %>%
select(latitude, longitude) %>%
summary()
## latitude longitude
## Min. :55.02 Min. :-166.2
## 1st Qu.:58.13 1st Qu.:-154.2
## Median :60.97 Median :-151.0
## Mean :61.41 Mean :-149.1
## 3rd Qu.:64.13 3rd Qu.:-145.6
## Max. :70.37 Max. :-131.3
lat <- c(55.02, 70.37) #latitude min, max
long <- c(-166.2, -131.3) # longitude min, max
bbox <- make_bbox(long, lat, f = 0.03)
#register_stadiamaps("API_code", write = FALSE)
stamen in a terrain style projection
and display the map.map1 <- get_stadiamap(bbox, maptype = "stamen_terrain", zoom=7)
## ℹ © Stadia Maps © Stamen Design © OpenMapTiles © OpenStreetMap contributors.
## ℹ 196 tiles needed, this may take a while (try a smaller zoom?)
ggmap(map1)
ggmap(map1) +
geom_point(data = grizzly, aes(longitude, latitude), size=0.6) +
labs(x= "Longitude", y= "Latitude", title="Grizzly Bear Observations")
Let’s switch to the wolves data. Brandell, Ellen E (2021), Serological dataset and R code for: Patterns and processes of pathogen exposure in gray wolves across North America, Dryad, Dataset.
summary(wolves)
## pop year age_cat sex
## Length:1986 Min. :1992 Length:1986 Length:1986
## Class :character 1st Qu.:2006 Class :character Class :character
## Mode :character Median :2011 Mode :character Mode :character
## Mean :2010
## 3rd Qu.:2016
## Max. :2019
##
## color lat long habitat
## Length:1986 Min. :33.89 Min. :-157.84 Min. : 254.1
## Class :character 1st Qu.:44.60 1st Qu.:-123.73 1st Qu.:10375.2
## Mode :character Median :46.83 Median :-110.99 Median :11211.3
## Mean :50.43 Mean :-116.86 Mean :12797.4
## 3rd Qu.:57.89 3rd Qu.:-110.55 3rd Qu.:11860.8
## Max. :80.50 Max. : -82.42 Max. :34676.6
##
## human pop_density pack_size standard_habitat
## Min. : 0.02 Min. : 3.74 Min. :3.55 Min. :-1.63390
## 1st Qu.: 80.60 1st Qu.: 7.40 1st Qu.:5.62 1st Qu.:-0.30620
## Median :2787.67 Median :11.63 Median :6.37 Median :-0.19650
## Mean :2335.38 Mean :14.91 Mean :6.47 Mean : 0.01158
## 3rd Qu.:3973.47 3rd Qu.:25.32 3rd Qu.:8.25 3rd Qu.:-0.11130
## Max. :6228.64 Max. :33.96 Max. :9.56 Max. : 2.88180
##
## standard_human standard_pop standard_packsize standard_latitude
## Min. :-0.9834 Min. :-1.13460 Min. :-1.7585 Min. :-1.805900
## 1st Qu.:-0.9444 1st Qu.:-0.74630 1st Qu.:-0.5418 1st Qu.:-0.636900
## Median : 0.3648 Median :-0.29760 Median :-0.1009 Median :-0.392600
## Mean : 0.1461 Mean : 0.05084 Mean :-0.0422 Mean :-0.000006
## 3rd Qu.: 0.9383 3rd Qu.: 1.15480 3rd Qu.: 1.0041 3rd Qu.: 0.814300
## Max. : 2.0290 Max. : 2.07150 Max. : 1.7742 Max. : 3.281900
##
## standard_longitude cav_binary cdv_binary cpv_binary
## Min. :-2.144100 Min. :0.0000 Min. :0.0000 Min. :0.0000
## 1st Qu.:-0.359500 1st Qu.:1.0000 1st Qu.:0.0000 1st Qu.:1.0000
## Median : 0.306900 Median :1.0000 Median :0.0000 Median :1.0000
## Mean :-0.000005 Mean :0.8529 Mean :0.2219 Mean :0.7943
## 3rd Qu.: 0.330200 3rd Qu.:1.0000 3rd Qu.:0.0000 3rd Qu.:1.0000
## Max. : 1.801500 Max. :1.0000 Max. :1.0000 Max. :1.0000
## NA's :321 NA's :21 NA's :7
## chv_binary neo_binary toxo_binary
## Min. :0.0000 Min. :0.0000 Min. :0.0000
## 1st Qu.:1.0000 1st Qu.:0.0000 1st Qu.:0.0000
## Median :1.0000 Median :0.0000 Median :0.0000
## Mean :0.8018 Mean :0.2804 Mean :0.4832
## 3rd Qu.:1.0000 3rd Qu.:1.0000 3rd Qu.:1.0000
## Max. :1.0000 Max. :1.0000 Max. :1.0000
## NA's :548 NA's :538 NA's :827
wolves %>%
summarise(wolf_populations=n_distinct(pop))
## # A tibble: 1 × 1
## wolf_populations
## <int>
## 1 17
mainland_wolves <- wolves %>%
filter(pop== "MT"| pop== "YNP"|pop== "GTNP" | pop=="MEXICAN" | pop=="SNF" |pop=="MI")
#or filter(wolves, pop %in% c("MT", "YNP", "GTNP", "SNF", "MI"))
mainland_wolves
## # A tibble: 1,169 × 23
## pop year age_cat sex color lat long habitat human pop_density
## <chr> <dbl> <chr> <chr> <chr> <dbl> <dbl> <dbl> <dbl> <dbl>
## 1 GTNP 2012 P M G 43.8 -111. 10375. 3924. 34.0
## 2 GTNP 2012 P F G 43.8 -111. 10375. 3924. 34.0
## 3 GTNP 2012 P F G 43.8 -111. 10375. 3924. 34.0
## 4 GTNP 2012 P M B 43.8 -111. 10375. 3924. 34.0
## 5 GTNP 2013 A F G 43.8 -111. 10375. 3924. 34.0
## 6 GTNP 2013 A M G 43.8 -111. 10375. 3924. 34.0
## 7 GTNP 2013 P M G 43.8 -111. 10375. 3924. 34.0
## 8 GTNP 2013 P M G 43.8 -111. 10375. 3924. 34.0
## 9 GTNP 2013 P M G 43.8 -111. 10375. 3924. 34.0
## 10 GTNP 2013 P F G 43.8 -111. 10375. 3924. 34.0
## # ℹ 1,159 more rows
## # ℹ 13 more variables: pack_size <dbl>, standard_habitat <dbl>,
## # standard_human <dbl>, standard_pop <dbl>, standard_packsize <dbl>,
## # standard_latitude <dbl>, standard_longitude <dbl>, cav_binary <dbl>,
## # cdv_binary <dbl>, cpv_binary <dbl>, chv_binary <dbl>, neo_binary <dbl>,
## # toxo_binary <dbl>
mainland_wolves %>%
select(lat, long) %>%
summary()
## lat long
## Min. :33.89 Min. :-110.99
## 1st Qu.:44.60 1st Qu.:-110.99
## Median :44.60 Median :-110.55
## Mean :43.95 Mean :-106.91
## 3rd Qu.:46.83 3rd Qu.:-109.17
## Max. :47.75 Max. : -86.82
stamen in a terrain-lines
projection and display the map.lat <- c(33.89, 47.75) #latitude min, max
long <- c(-110.99, -86.82 ) # longitude min, max
bbox <- make_bbox(long, lat, f = 0.05)
#register_stadiamaps("API_code", write = FALSE)
map2 <- get_stadiamap(bbox, maptype = "stamen_terrain", zoom=8)
## ℹ © Stadia Maps © Stamen Design © OpenMapTiles © OpenStreetMap contributors.
## ℹ 300 tiles needed, this may take a while (try a smaller zoom?)
ggmap(map2) +
geom_point(data = mainland_wolves, aes(long, lat), size=3) +
labs(x= "Longitude", y= "Latitude", title="Wolf Observations")
fill and color by population.ggmap(map2) +
geom_point(data = mainland_wolves, aes(long, lat, color=pop), size=3) +
labs(x= "Longitude", y= "Latitude", title="Wolf Observations")
```
Please be sure that you check the keep md file in the
knit preferences.